package com.woniuxy.producer;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 延迟队列生产者
 */
@Component
public class DelayExchangeProducer {
    @Autowired
    RabbitTemplate rabbitTemplate;

    public void send(String msg,String routerKey,Integer ttl){
        rabbitTemplate.convertAndSend("delayExchange", routerKey, msg, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setDelay(ttl);
                return message;
            }
        });
    }


}
